import { ElMessageBox } from "element-plus";
import { EventSourcePolyfill } from "event-source-polyfill";

const eventSource = new EventSourcePolyfill(window._apiUrl.webUrl+'sse',{
    headers:{
        Authorization: localStorage.getItem('token'),
        timeout:0 
    }
})

eventSource.addEventListener('open', (e)=>{
    console.log('open sse successful')
})

eventSource.addEventListener('message', (e)=>{
    ElMessageBox.confirm(e.data,'SSE消息',{type:'info'}).then(()=>{
        eventSource.close()
    })
})

eventSource.addEventListener('error', (e)=>{
    console.log(e)
})